package com.molyfun.parents.activity.store.view;

import android.content.Context;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.rest.bean.ProductDetailResponse;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:10/18/16.
 */
public class OrderCellView extends LinearLayout implements View.OnClickListener{

    protected LayoutInflater layoutInflater;

    @InjectView(R.id.img_product_cover)
    ImageView mProductCover;
    @InjectView(R.id.product_name)
    TextView mProductName;
    @InjectView(R.id.price_now)
    TextView mPriceNow;
    @InjectView(R.id.price_old)
    TextView mPriceOld;
    @InjectView(R.id.open_service)
    TextView mOpenService;
    @InjectView(R.id.product_age_range)
    TextView mProductAgeRange;
    @InjectView(R.id.product_time_range)
    TextView mProductTimeRange;

    private Context context;
    private ProductDetailResponse.ProductDetailBean mProductDetailBean;

    public OrderCellView(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    public OrderCellView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public OrderCellView(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        layoutInflater.inflate(R.layout.widget_product, this);
        ButterKnife.inject(this);
    }

    public void initData(ProductDetailResponse.ProductDetailBean productDetailBean) {
        if(productDetailBean == null){
            return;
        }
        mProductDetailBean = productDetailBean;
        mProductName.setText(productDetailBean.getName());
        mPriceNow.setText("￥" + mProductDetailBean.getDiscountprice());
        mPriceOld.setText("￥" + mProductDetailBean.getPrice());
        mPriceOld.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG ); //中间横线
        mProductAgeRange.setText(mProductDetailBean.getApplicablescope());
        mProductTimeRange.setText(mProductDetailBean.getExpdate() + "天");
        mOpenService.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.open_service:
                //TODO 跳转到详情页
//                OrderDetailActivity.startActivity(getContext(), mProductDetailBean);
                break;
            default:
                break;
        }
    }


}